home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / map4viewslayout.py < prev    next >
Text File  |  2004-01-05  |  9KB  |  361 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Plug-in which define the 4-views screen layouts.
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/map4viewslayout.py,v 1.2 2000/06/03 10:25:30 alexander Exp $
  12.  
  13.  
  14.  
  15. Info = {
  16.    "plug-in":       "4-Views Layout",
  17.    "desc":          "4-views Screen Layouts.",
  18.    "date":          "12 nov 98",
  19.    "author":        "Armin Rigo",
  20.    "author e-mail": "arigo@planetquake.com",
  21.    "quark":         "Version 5.1" }
  22.  
  23.  
  24. from quarkpy.mapmgr import *
  25.  
  26.  
  27. #
  28. # The 4-Views Layout is implemented as a subclass of the base class MapLayout.
  29. #
  30.  
  31. class FourViewsLayout(MapLayout):
  32.     "The 4-views layout, abstract class for FourViewsLayout1 and FourViewsLayout2."
  33.  
  34.     def buildbase(self, form):
  35.  
  36.         #
  37.         # We put the standard left panel first.
  38.         #
  39.  
  40.         self.bs_leftpanel(form)
  41.  
  42.         #
  43.         # Create the four views.
  44.         #
  45.  
  46.         self.ViewXY = form.mainpanel.newmapview()
  47.         self.ViewXZ = form.mainpanel.newmapview()
  48.         self.ViewYZ = form.mainpanel.newmapview()
  49.         self.View3D = form.mainpanel.newmapview()
  50.  
  51.         #
  52.         # Put these 4 views in the view lists.
  53.         #
  54.  
  55.         self.views[:] = [self.ViewXY, self.ViewXZ, self.ViewYZ, self.View3D]
  56.         self.baseviews = self.views[:]
  57.  
  58.         #
  59.         # Setup initial display parameters.
  60.         #
  61.  
  62.         scale = 0.25   # default value
  63.  
  64.         self.ViewXY.info = {
  65.           "type": "XY",     # XY view
  66.           "angle": 0.0,     # compass angle
  67.           "scale": scale,   # scale
  68.           "vangle": 0.0}    # vertical angle
  69.  
  70.         self.ViewXZ.info = {
  71.           "type": "XZ",     # XZ view
  72.           "angle": 0.0,
  73.           "scale": scale,
  74.           "vangle": 0.0}
  75.  
  76.         self.ViewYZ.info = {
  77.           "type": "YZ",     # YZ view
  78.           "angle": 0.0,
  79.           "scale": scale,
  80.           "vangle": 0.0}
  81.  
  82.         self.View3D.info = {
  83.           "type": "3D"}     # 3D view
  84.  
  85.     #
  86.     # The following function is called when the configuration changed.
  87.     # We show or hide the red lines here.
  88.     #
  89.  
  90.     def setupchanged(self, level):
  91.  
  92.         #
  93.         # First call the inherited "setupchanged".
  94.         #
  95.  
  96.         MapLayout.setupchanged(self, level)
  97.  
  98.  
  99.         #
  100.         # Read the old flags and set both red lines by default.
  101.         #
  102.  
  103.         flagsXY = self.ViewXY.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  104.         flagsXZ = self.ViewXZ.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  105.  
  106.         #
  107.         # Remove the 2nd red line if required.
  108.         #
  109.  
  110.         if not MapOption("RedLines2"):
  111.             flagsXY = flagsXY &~ MV_TOPREDLINE
  112.             flagsXZ = flagsXZ &~ MV_BOTTOMREDLINE
  113.  
  114.         #
  115.         # Update the flags.
  116.         #
  117.  
  118.         self.ViewXY.flags = flagsXY
  119.         self.ViewXZ.flags = flagsXZ
  120.  
  121.     #
  122.     # The following function is called to compute the limits of
  123.     # the visible (non-grayed-out) areas for each map view.
  124.     #
  125.  
  126.     def setupdepth(self, view):
  127.  
  128.         #
  129.         # First check the "view" parameter.
  130.         #
  131.  
  132.         if not (view in (self.ViewXY, self.ViewXZ, self.ViewYZ)):
  133.             return
  134.  
  135.         #
  136.         # To compute the visible areas for the XY view, we
  137.         # get the rectangular area (in pixels) of the XZ view.
  138.         #
  139.  
  140.         x1,y1,x2,y2 = self.ViewXZ.redlinesrect
  141.  
  142.         #
  143.         # The line below does this :
  144.         #  * take a corner of the above rectangle
  145.         #  * compute the 3D coordinates of any point above this corner
  146.         # This gives a 3D point that is at the top limit of the visible area for the XY view.
  147.         #  * project this 3D point on the XY view
  148.         #  * keep only the z coordinate (i.e. the depth) of this projection
  149.         # This gives the depth of the top limit, which is what we wanted.
  150.         #
  151.         # The second line does the same for the other corner, which gives
  152.         # the bottom limit of the visible area.
  153.         #
  154.  
  155.         xydepth = (self.ViewXY.proj(self.ViewXZ.space(x1, y1, 0.0)).z,
  156.                    self.ViewXY.proj(self.ViewXZ.space(x2, y2, 0.0)).z)
  157.  
  158.         #
  159.         # Do it again for the XZ view...
  160.         #
  161.  
  162.         x1,y1,x2,y2 = self.ViewXY.redlinesrect
  163.         corner1 = self.ViewXY.space(x1, y1, 0.0)
  164.         corner2 = self.ViewXY.space(x2, y2, 0.0)
  165.         
  166.         xzdepth = (self.ViewXZ.proj(corner2).z,
  167.                    self.ViewXZ.proj(corner1).z)
  168.  
  169.         #
  170.         # Do it again for the YZ view...
  171.         #
  172.  
  173.         yzdepth = (self.ViewYZ.proj(corner1).z,
  174.                    self.ViewYZ.proj(corner2).z)
  175.  
  176.         #
  177.         # Depending on the draw mode, items may or may not be grayed
  178.         # out. If they are, we must redraw a view when the other one
  179.         # is scrolled, in case objects came in or out of view. This
  180.         # is done by calling "setdepth". Otherwise, we directly set
  181.         # the map view's "depth" attribute, which doesn't redraw the
  182.         # view.
  183.         #
  184.  
  185.         redraw = self.editor.drawmode & DM_MASKOOV
  186.  
  187.         if redraw and (view is not self.ViewXY):
  188.             self.ViewXY.setdepth(xydepth)
  189.         else:
  190.             self.ViewXY.depth = xydepth
  191.  
  192.         if redraw and (view is not self.ViewXZ):
  193.             self.ViewXZ.setdepth(xzdepth)
  194.         else:
  195.             self.ViewXZ.depth = xzdepth
  196.  
  197.         if redraw and (view is not self.ViewYZ):
  198.             self.ViewYZ.setdepth(yzdepth)
  199.         else:
  200.             self.ViewYZ.depth = yzdepth
  201.  
  202.  
  203.     #
  204.     # Functions to read and store the layout (window positions,...)
  205.     # in the Setup.
  206.     #
  207.  
  208.     def readconfig(self, config):
  209.         MapLayout.readconfig(self, config)
  210.         secs = config["secs"]
  211.         if type(secs)==type(()) and len(secs)==2:
  212.             self.editor.form.mainpanel.sections = (secs[:1], secs[1:])
  213.  
  214.     def writeconfig(self, config):
  215.         MapLayout.writeconfig(self, config)
  216.         hsec, vsec = self.editor.form.mainpanel.sections
  217.         config["secs"] = hsec[0], vsec[0]
  218.  
  219.  
  220.  
  221.  
  222.  
  223. class FourViewsLayout1(FourViewsLayout):
  224.  
  225.     shortname = "4 views (a)"
  226.  
  227.     def buildscreen(self, form):
  228.  
  229.         #
  230.         # Build the base.
  231.         #
  232.  
  233.         self.buildbase(form)
  234.  
  235.         #
  236.         # Divide the main panel into 4 sections.
  237.         # horizontally, 2 sections split at 55% of the width
  238.         # vertically, 2 sections split at 40% of the height
  239.         #
  240.  
  241.         form.mainpanel.sections = ((0.55, ), (0.4,))
  242.  
  243.         #
  244.         # Put the XY view in the section (0,1), i.e. left down.
  245.         #
  246.  
  247.         self.ViewXY.section = (0,1)
  248.  
  249.         #
  250.         # The XZ view is in the section (0,0) (it is there by default).
  251.         #
  252.  
  253.         #
  254.         # Put the YZ view in the section (1,0).
  255.         #
  256.  
  257.         self.ViewYZ.section = (1,0)
  258.  
  259.         #
  260.         # Put the 3D view in the section (1,1).
  261.         #
  262.  
  263.         self.View3D.section = (1,1)
  264.  
  265.         #
  266.         # Link the horizontal position of the XZ view to that of the
  267.         # XY view, and the vertical position of the XZ and YZ views,
  268.         # and remove the scroll bars of the XZ view.
  269.         #
  270.  
  271.         self.sblinks.append((0, self.ViewXY, 0, self.ViewXZ))
  272.         self.sblinks.append((1, self.ViewYZ, 1, self.ViewXZ))
  273.         self.sblinks.append((1, self.ViewXY, 0, self.ViewYZ))
  274.         self.ViewXZ.flags = self.ViewXZ.flags &~ (MV_HSCROLLBAR | MV_VSCROLLBAR)
  275.  
  276.         #
  277.         # Either hide the h. scroll bar of the YZ view, or link back the XY view to the YZ.
  278.         #
  279.  
  280.         self.ViewYZ.flags = self.ViewYZ.flags &~ MV_HSCROLLBAR
  281.         #self.sblinks.append((0, self.ViewYZ, 1, self.ViewXY))
  282.  
  283.  
  284.  
  285.  
  286.  
  287. class FourViewsLayout2(FourViewsLayout):
  288.  
  289.     shortname = "4 views (b)"
  290.  
  291.     def buildscreen(self, form):
  292.  
  293.         #
  294.         # Build the base.
  295.         #
  296.  
  297.         self.buildbase(form)
  298.  
  299.         #
  300.         # Divide the main panel into 4 sections.
  301.         # horizontally, 2 sections split at 45% of the width
  302.         # vertically, 2 sections split at 55% of the height
  303.         #
  304.  
  305.         form.mainpanel.sections = ((0.45, ), (0.55,))
  306.  
  307.         #
  308.         # Put the XY view in the section (1,0)
  309.         #
  310.  
  311.         self.ViewXY.section = (1,0)
  312.  
  313.         #
  314.         # Put the XZ view in the section (1,1).
  315.         #
  316.  
  317.         self.ViewXZ.section = (1,1)
  318.  
  319.         #
  320.         # Put the YZ view in the section (0,1).
  321.         #
  322.  
  323.         self.ViewYZ.section = (0,1)
  324.  
  325.         #
  326.         # The 3D view is in the section (0,0) (it is there by default).
  327.         #
  328.  
  329.         #
  330.         # Link the horizontal position of the XZ view to that of the
  331.         # XY view, and the vertical position of the XZ and YZ views,
  332.         # and remove the extra scroll bars.
  333.         #
  334.  
  335.         self.sblinks.append((0, self.ViewXZ, 0, self.ViewXY))
  336.         self.sblinks.append((1, self.ViewXZ, 1, self.ViewYZ))
  337.         self.sblinks.append((1, self.ViewXY, 0, self.ViewYZ))
  338.         self.ViewYZ.flags = self.ViewYZ.flags &~ (MV_HSCROLLBAR | MV_VSCROLLBAR)
  339.         self.ViewXY.flags = self.ViewXY.flags &~ MV_HSCROLLBAR
  340.  
  341.  
  342.  
  343.  
  344. #
  345. # Register the new layouts.
  346. #
  347.  
  348. LayoutsList.append(FourViewsLayout1)
  349. LayoutsList.append(FourViewsLayout2)
  350.  
  351.  
  352. # ----------- REVISION HISTORY ------------
  353. #
  354. #
  355. # $Log: map4viewslayout.py,v $
  356. # Revision 1.2  2000/06/03 10:25:30  alexander
  357. # added cvs headers
  358. #
  359. #
  360. #
  361. #